<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Grom Hellscream
 * Date: 11/6/12
 * Time: 6:42 AM
 * To change this template use File | Settings | File Templates.
 */
defined('_JEXEC') or die;

class VastViewDonvitheokhoi extends JViewLegacy
{
    protected $form;
    protected $item;
    protected $state;
    protected $canDo;
    /**
     * Display the view
     */
    public function display($tpl = null)
    {
        // Initialiase variables.
        $this->form		= $this->get('Form');
        $this->item		= $this->get('Item');
        $this->state	= $this->get('State');
        $this->canDo	= DonvisHelper::getActions();

        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode("\n", $errors));
            return false;
        }

        $this->addToolbar();
        parent::display($tpl);
    }

    /**
     * Add the page title and toolbar.
     *
     * @since	1.6
     */
    protected function addToolbar()
    {
        JRequest::setVar('hidemainmenu', true);
        $isNew		= ($this->item->id == 0);
        $id = JRequest::getInt('khoi_id');
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('a.*');
        $query->from('#__khoi AS a');
        $query->where('a.id = ' . $id);

        $db->setQuery($query);
        $tmp = $db->loadObject();

        if ($tmp !== NULL)
            JToolBarHelper::title(sprintf(JText::_('COM_VAST_DONVITHEOKHOI_DETAIL'), $tmp->ten), 'head vm_manufacturer_48');
        else
            JToolBarHelper::title(JText::_('COM_VAST_DONVITHEOKHOI_DETAIL'), 'head vm_manufacturer_48');
            
        JToolBarHelper::divider();

        if (JFactory::getUser()->authorise('vast.khoi.add.donvi', 'com_vast'))
        {
            JToolBarHelper::save2new('donvitheokhoi.save2new', 'COM_VAST_DONVI_JTOOLBAR_SAVE2NEW');
            JToolBarHelper::save2copy('donvitheokhoi.save2copy', 'COM_VAST_DONVI_JTOOLBAR_SAVE2COPY');
            JToolBarHelper::save('donvitheokhoi.save', 'COM_VAST_DONVI_JTOOLBAR_SAVE');
            JToolBarHelper::cancel('donvitheokhoi.cancel', $isNew ? 'COM_VAST_DONVI_JTOOLBAR_CANCEL' : 'COM_VAST_DONVI_JTOOLBAR_CLOSE');            
        }
    }
}